package com.xcx.robot.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: 邢晨旭
 * @Date: 2021/6/17 09:11
 * @Description:
 */
@Component
public class RedisUtil<T> {

    @Resource
    RedisTemplate<String, Object> redisTemplate;

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public String getJson(String key) {
        return JSONArray.toJSONString(this.get(key));
    }

    public T getResult(String key, Class<T> tClass) {
        return JSONObject.parseObject(getJson(key), tClass);
    }

}
